package bom.pojo.organization;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Author: Fancyears·Maylos·Malvis
 * @Description: 用户单个权限对象，针对读页面的操作
 * @Date: Created in  2018/11/27 14:48
 * @Modified By:
 */
@Data
public class UserRole {
    /**
     * 主键
     */
    private Long id;
    /**
     * 角色英文名
     */
    private String name;
    /**
     * 角色中文名
     */
    private String roleName;
    /**
     * 已授权的菜单树
     */
    private List<Tree> treeList;

    /** 临时采访菜单数集合的数据*/
    private String treeArray;
    public void packagingTrees(String treeArray) {
        Tree tree = null;
        List<Tree> trees = new ArrayList<>();
        for (String id : treeArray.split(",")) {
            if (!id.isEmpty()) {
                tree = new Tree(Long.parseLong(id));
                trees.add(tree);
            }
        }
        this.setTreeList(trees);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        UserRole role = (UserRole) o;
        return id == role.id;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
